Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@aws-cdk/aws-sns
Advanced tools
@aws-cdk/aws-sns is an AWS Cloud Development Kit (CDK) library that allows you to define Amazon Simple Notification Service (SNS) topics and subscriptions in your AWS infrastructure as code. This package provides a high-level, object-oriented abstraction to create and manage SNS resources programmatically.
Create an SNS Topic
This code sample demonstrates how to create an SNS topic with a display name using the AWS CDK.
const sns = require('@aws-cdk/aws-sns');
const cdk = require('@aws-cdk/core');
class MyStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const topic = new sns.Topic(this, 'MyTopic', {
displayName: 'My Cool Topic'
});
}
}
const app = new cdk.App();
new MyStack(app, 'MyStack');
Add an Email Subscription to an SNS Topic
This code sample shows how to add an email subscription to an SNS topic using the AWS CDK.
const sns = require('@aws-cdk/aws-sns');
const subs = require('@aws-cdk/aws-sns-subscriptions');
const cdk = require('@aws-cdk/core');
class MyStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const topic = new sns.Topic(this, 'MyTopic');
topic.addSubscription(new subs.EmailSubscription('example@example.com'));
}
}
const app = new cdk.App();
new MyStack(app, 'MyStack');
Add a Lambda Subscription to an SNS Topic
This code sample demonstrates how to add a Lambda function as a subscription to an SNS topic using the AWS CDK.
const sns = require('@aws-cdk/aws-sns');
const subs = require('@aws-cdk/aws-sns-subscriptions');
const lambda = require('@aws-cdk/aws-lambda');
const cdk = require('@aws-cdk/core');
class MyStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const topic = new sns.Topic(this, 'MyTopic');
const myFunction = new lambda.Function(this, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('lambda')
});
topic.addSubscription(new subs.LambdaSubscription(myFunction));
}
}
const app = new cdk.App();
new MyStack(app, 'MyStack');
The aws-sdk package is the official AWS SDK for JavaScript, which provides low-level APIs for interacting with AWS services, including SNS. Unlike @aws-cdk/aws-sns, which is used for defining infrastructure as code, aws-sdk is used for making API calls to AWS services at runtime.
The serverless framework is a toolkit for deploying and operating serverless architectures, including AWS Lambda and SNS. It provides a higher-level abstraction compared to @aws-cdk/aws-sns and is focused on deploying serverless applications rather than defining infrastructure as code.
Pulumi is an infrastructure as code tool that supports multiple cloud providers, including AWS. It allows you to define and manage cloud resources using familiar programming languages. Pulumi provides similar functionalities to @aws-cdk/aws-sns but offers a different approach and supports multiple clouds.
Add an SNS Topic to your stack:
import sns = require('@aws-cdk/aws-sns');
const topic = new sns.Topic(stack, 'Topic', {
displayName: 'Customer subscription topic'
});
Various subscriptions can be added to the topic by calling the .subscribeXxx()
methods on the
topic.
Add an HTTPS Subscription to your topic:
const myTopic = new sns.Topic(stack, 'MyTopic');
myTopic.subscribeUrl('MyHttpsSubscription', 'https://foobar.com/');
Subscribe a queue to the topic:
Example of subscribing a queue to a topic
Note that subscriptions of queues in different accounts need to be manually confirmed by reading the initial message from the queue and visiting the link found in it.
SNS topics can be used as targets for CloudWatch event rules:
Example of CloudWatch Event rules
This will result in adding a target to the event rule and will also modify the topic resource policy to allow CloudWatch events to publish to the topic.
0.19.0 (2018-12-04)
ecr.RepositoryRef
has been replaced by ecr.IRepository
, which
means that RepositoryRef.import
is now Repository.import
. Futhermore, the CDK
Toolkit must also be upgraded since the docker asset protocol was modified.
IRepository.grantUseImage
was renamed to IRepository.grantPull
.addBuildToPipeline
was renamed to addToPipeline
and addTestToPipeline
was renamed to addPipelineToTest
in order to align
with naming conventions.CloudFormationCapabilities.IAM
renamed to
CloudFormation.AnonymousIAM
and PipelineCloudFormationDeployActionProps.capabilities?: CloudFormationCapabilities[]
has been changed to
PipelineCloudFormationDeployActionProps.capabilities?: CloudFormationCapabilities
no longer an array.
PipelineCloudFormationDeployActionProps.fullPermissions?:
has been
renamed to PipelineCloudFormationDeployActionProps.adminPermissions:
and is required instead of optional.<a name="0.18.1"></a>
FAQs
The CDK Construct Library for AWS::SNS
We found that @aws-cdk/aws-sns demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.